'''
Created on 14/03/2010

@author: Usuario
'''

import sys
import os
import pkg_resources
from datetime import datetime
from iasna_core.analysis import Indicators
from iasna_core.analysis.settings import DIRS

args = sys.argv
print "executing", args

try:
    os.mkdir(DIRS['CORE_MEDIA_ROOT'])
    os.mkdir(DIRS['CORE_RESULTS_ROOT'])
    os.mkdir(DIRS['CORE_GRAPH_IMG_ROOT'])
except:
    print '\nWarning, while creating path directories it throws an exception, please be sure these directories exist:'
    print DIRS['CORE_MEDIA_ROOT'], ',', DIRS['CORE_RESULTS_ROOT'], ',', DIRS['CORE_GRAPH_IMG_ROOT']

help = '\nIASNA core\nTo use: iasna.exe xml_file_path [datetime_start datetime_end [minutes]]\ndatetime_start and datetime_end should be type as: "12/30/2005 19:50:00"\n'

if len(args) == 2:
    if args[1] == '-h' : print help
    elif args[1] == '--help': print help
    else: Indicators.compute_indicators(args[1], None, None, 0)
elif len(args) == 4: Indicators.compute_indicators(args[1], datetime.strptime(args[2], '%m/%d/%Y %H:%M:%S'), datetime.strptime(args[3], '%m/%d/%Y %H:%M:%S'), 0)
elif len(args) == 5: Indicators.compute_indicators(args[1], datetime.strptime(args[2], '%m/%d/%Y %H:%M:%S'), datetime.strptime(args[3], '%m/%d/%Y %H:%M:%S'), int(args[4]))
else: print help

print '\nFinaliza exitosamente.'

